home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 16
/
CU Amiga Magazine's Super CD-ROM 16 (1997-10-16)(EMAP Images)(GB)[!][issue 1997-11].iso
/
CUCD
/
Utilities
/
moreHTML
/
Source
/
mylist.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-09-11
|
2KB
|
130 lines
// MyList
// © Dirk Holtwick, 1997
/// Includes
#include <clib/alib_protos.h>
#include <proto/exec.h>
#include <exec/memory.h>
#include "mylist.h"
///
/// Example
/*
Simple list routines do works like this:
struct Data {APTR succ; ... };
struct MyList *mylist;
if(mylist = MyCreateList(sizeof(struct Data),100))
{
item = MyAddItem(mylist);
MyDisposeList(mylist);
}
*/
///
/// MyCreateList
struct MyList *MyCreateList(register ULONG size, register ULONG pudsize)
{
register struct MyList *mylist;
if(mylist = AllocVec(sizeof(struct MyList), MEMF_CLEAR))
{
mylist->size = size;
mylist->pudsize = pudsize;
if(mylist->pool = LibCreatePool(MEMF_CLEAR, (size * pudsize), size))
{
return(mylist);
}
FreeVec(mylist);
}
return(0);
}
///
/// MyDisposeList
void MyDisposeList(register struct MyList *mylist)
{
if(mylist)
{
if(mylist->pool) LibDeletePool(mylist->pool);
FreeVec(mylist);
}
}
///
/// MyAddItem
APTR MyAddItem(register struct MyList *mylist)
{
register struct MyItem *item;
if(mylist)
{
if(item = LibAllocPooled(mylist->pool, mylist->size))
{
if(mylist->first)
mylist->last->next = item;
else
mylist->first = item;
mylist->last = item;
item->next = 0;
return(item);
}
}
return(0);
}
///
/// MyPushItem
APTR MyPushItem(register struct MyList *mylist)
{
register struct MyItem *item;
// Insert an item at the beginning of the list
if(mylist)
{
if(item = LibAllocPooled(mylist->pool, mylist->size))
{
if(mylist->last)
mylist->last = item;
item->next = mylist->first;
mylist->first = item;
mylist->last->next = 0;
return(item);
}
}
return(0);
}
///
/// MyPullItem
APTR MyPullItem(register struct MyList *mylist)
{
register struct MyItem *item;
// Insert an item at the beginning of the list
if(mylist)
{
if(item = LibAllocPooled(mylist->pool, mylist->size))
{
if(mylist->last)
mylist->last = item;
item->next = mylist->first;
mylist->first = item;
mylist->last->next = 0;
return(item);
}
}
return(0);
}
///